﻿using System;
using System.IO;

class ParseAnURLAddress
{
    static void Main()
    {
        //Exercise 12.
        //Write a program that parses an URL address given in the format:
        //     [protocol]://[server]/[resource]
		//and extracts from it the [protocol], [server] and [resource] elements. 
        //For example from the URL http://www.devbg.org/forum/index.php the following information should be extracted:
		//[protocol] = "http"
		//[server] = "www.devbg.org"
		//[resource] = "/forum/index.php"

        string address = @"http://www.devbg.org/forum/index.php";
               
        string protocol = "";
        int colonIndex = address.IndexOf(':');
        if (colonIndex != -1)
        {
            protocol = address.Substring(0, colonIndex);
        }
        Console.WriteLine("[protocol] = \"{0}\"", protocol);

        string server = "";
        for (int i = colonIndex + 3; i < address.Length; i++)
        {
            if (address[i] != '/')
            {
                server = server + address[i];                
            }
            else
            {
                break;
            }
        }
        Console.WriteLine("[server] = \"{0}\"", server);

        string resource = "";
        int slashIndex = address.IndexOf('/', colonIndex + 3);
        for (int i = slashIndex; i < address.Length; i++)
        {
            resource = resource + address[i];
        }
        Console.WriteLine("[resource] = \"{0}\"", resource);
        
    }
}

